import axios from 'axios';
import store from '../store';

function createHeaders () {
  return { 'AUTHORIZATION': store.state.token, 'Content-Type': 'application/json' };
}

// 所有领域
export const getLingyu = () => axios.post(process.env.VUE_APP_COSWEBAPIURL + '/research/field/getAllIndustryList', {}, {
  headers: createHeaders()
});

// 所有分析师
export const getAllAnalystList = () => axios.post(process.env.VUE_APP_COSWEBAPIURL + '/research/analyst/getAllAnalystList', {}, {
  headers: createHeaders()
});

/**
 * 退出登录
 * @param {{userCode:string}} data
 * @returns
 */
export const logout = (data) => axios.post(process.env.VUE_APP_COSWEBAPIURL + '/api/user/logout', data, {
  headers: createHeaders()
});

/**
 * 修改密码
 * @param {{branchNo:string, userCode:string, password:string,newPassword:string, acctType:string, acctCode:string}} data
 * @returns
 */
export const modifyPassword = (data) => axios.post(process.env.VUE_APP_COSWEBAPIURL + '/api/user/updatePwdManageService', data, {
  headers: createHeaders()
});

 // 获取文件流
 export const getFileStreamListByFileCodes = (data) =>
 axios.post(process.env.VUE_APP_COSWEBAPIURL + '/servicefile/getFilesStreamListByFileCodes', data, { responseType: 'blob' });

 export const downloadPdf = (data) => {
  if (!data) {
    return;
  }
  const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }));
  window.open(url);
  return url;
};
